package com.zzyl.controller;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;


    @GetMapping
    @ApiOperation(value = "分页查询护理项目" ,notes = "分页查询护理项目")
    public ResponseResult selectByPage(
           @ApiParam(value = "护理项目名称") String name,
           @ApiParam(value = "护理项目状态0-禁用  1-启用") Integer status,
           @ApiParam(value = "页码") @RequestParam(defaultValue = "1") Integer pageNum,
           @ApiParam(value = "每页显示的条数") @RequestParam(defaultValue = "10")  Integer pageSize
    ){
        PageResponse<NursingProjectVo> pageResponse =   nursingProjectService.selectByPage(name,status,pageNum,pageSize);

        return success(pageResponse);
    }

    @PostMapping
    @ApiOperation(value = "新增护理项目" ,notes = "新增护理项目")
    public ResponseResult add( @ApiParam(value = "护理项目DTO类") @RequestBody NursingProjectDto nursingProjectDto){

       nursingProjectService.add(nursingProjectDto);

        return success();
    }
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询护理项目" ,notes = "根据id查询护理项目")
    public ResponseResult getById( @ApiParam(value = "护理项目DTO类") @PathVariable("id") Long id){

       NursingProjectVo vo =  nursingProjectService.getById(id);

        return success(vo);
    }
    @PutMapping
    @ApiOperation(value = "修改护理项目" ,notes = "修改护理项目")
    public ResponseResult update( @ApiParam(value = "护理项目DTO类") @RequestBody NursingProjectDto nursingProjectDto){

        nursingProjectService.update(nursingProjectDto);

        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "修改护理项目的状态" ,notes = "修改护理项目的状态")
    public ResponseResult updateStatus(
            @ApiParam(value = "护理项目id") @PathVariable("id") Long id ,
            @ApiParam(value = "护理项目状态") @PathVariable("status") Integer status
    ){

        nursingProjectService.updateStatus(id,status);

        return success();
    }

    @GetMapping("/all")
    @ApiOperation(value = "查询所有护理项目" ,notes = "查询所有护理项目")
    public ResponseResult getAll(){

        List<NursingProjectVo>   voList =  nursingProjectService.getAll();

        return success(voList);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据id删除护理项目" ,notes = "根据id删除护理项目")
    public ResponseResult deleteById( @ApiParam(value = "护理项目id") @PathVariable("id") Long id){

         nursingProjectService.deleteById(id);

        return success();
    }
}
